__kernel void f(__global const float *a, __global const float *b, __global int *c, int maxIter)
{
	int gid = get_global_id(0);
	int iter = 0;
	float real, img, real1, real2, img1, img2, realsqr, imgsqr;
	real = real1 = a[gid];
	img = img1 = b[gid];
	realsqr = real1 * real1;
	imgsqr = img1 * img1;
	
	while((iter < maxIter) && ((realsqr + imgsqr) < 4))
	{
		real2 = real1 * real1 - img1 * img1 + real;
		img2 = 2 * real1 * img1 + img;
		
		real1 = real2 * real2 - img2 * img2 + real;
		img1 = 2 * real2 * img2 + img;
		
		realsqr = real2 * real2;
		imgsqr = img2 * img2;
		real1 = realsqr - imgsqr + real;
		img1 = 2 * real2 * img2 + img;
		
		iter+=2;

	}
	c[gid] = iter;
}
